import java.util.Scanner;

public class Test {
    static Animal[] animals = new Animal[3];
    static Scanner input = new Scanner(System.in);
    static int num;
    public static void showAnimal(){
        System.out.println("动物名字\t\t腿的条数\t\t动物叫");
        for (int i = 0; i < animals.length; i++) {
            if (animals[i] instanceof Terrestrial) {
                String name = animals[i].getName();
                int legNum = ((Terrestrial) animals[i]).getLegNum();
                System.out.print(name + "\t\t" + legNum + "\t\t");
                animals[i].shout();
            }else {
                String name = animals[i].getName();
                System.out.print(name + "\t\t" + 0 + "\t\t");
                animals[i].shout();
            }
        }
        System.out.println("是否要继续修改数据：按0进行修改操作，其他任意数字键退出");
    }
    public static void modifyAnimal()throws Exception{
        String[] names = new String[3];
        int[] number = new int[3];
        System.out.println("请输入猫的名称：");
        names[0] = input.next();
        System.out.println("请输入猫腿的条数：");
        number[0] = input.nextInt();
        if (number[0] !=4){
            throw new Exception("猫是有4条腿");
        }
        System.out.println("请输入鸭子的名称：");
        names[1] = input.next();
        System.out.println("请输入鸭子腿的条数：");
        number[1] = input.nextInt();
        if (number[1] !=2){
            throw new Exception("鸭子是有2条腿");
        }
        System.out.println("请输入海豚的名称：");
        names[2] = input.next();
        animals[0] = new Cat(names[0],number[0]);
        animals[1] = new Duck(names[1],number[1]);
        animals[2] = new Dolphin(names[2]);
    }

    public static void main(String[] args) {
        animals[0] = new Cat("加菲猫",4);
        animals[1] = new Duck("唐老鸭",2);
        animals[2] = new Dolphin("海豚奇奇");
        showAnimal();
        num = input.nextInt();
        while (num == 0){
            try{
                modifyAnimal();
            }catch (Exception e){
                e.printStackTrace();
            }finally {
                showAnimal();
                num = input.nextInt();
            }
        }
        System.out.println("谢谢使用！");
    }
}
